﻿<template>
  <div class="l-rblock l-form-viewer" style="padding: 8px">
    <el-form :model="formData" :rules="rules" size="mini" labelPosition="right" labelWidth="80px" ref="form">
      <div class="l-auto-window only-tabs">
        <el-tabs v-model="activeName" type="card">
          <el-tab-pane class="l-tabs-container" :label="$t('主表信息')" name="tab0">
            <el-row :gutter="0">
              <div class="l-rblock">
                <el-col v-if="lr_formLookAuth('user_f_account')" :span="24">
                  <el-form-item label="单行文本" prop="user_f_account">
                    <el-input
                      :disabled="!lr_formEditAuth('user_f_account')"
                      v-model="formData.user_f_account"
                      :placeholder="$t('请输入')"
                    >
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="24">
                  <el-form-item label="真实姓名" prop="user_f_realname">
                    <el-input v-model="formData.user_f_realname" :placeholder="$t('请输入')"> </el-input>
                  </el-form-item>
                </el-col>
                <el-col v-if="lr_formLookAuth('user_f_password')" :span="24">
                  <el-form-item label="密码" prop="user_f_password">
                    <el-input
                      type="password"
                      :disabled="!lr_formEditAuth('user_f_password')"
                      v-model="formData.user_f_password"
                      :placeholder="$t('请输入')"
                    >
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col v-show="false" :span="24">
                  <el-form-item label="GUID主键" prop="user_f_userid">
                    <l-guid size="mini" v-model="formData.user_f_userid" />
                  </el-form-item>
                </el-col>
              </div>
            </el-row>
          </el-tab-pane>
        </el-tabs>
      </div>
    </el-form>
  </div>
</template>
<script>
//const api = window.$api.testflow.testCode;
const apiUser = window.$api.organization.user;
export default {
  data() {
    return {
      moduleCode: "testFlow_testCode",
      activeName: "tab0",
      formData: {
        user_f_account: "", // 单行文本
        user_f_password: "", // 密码
        user_f_userid: "", // GUID主键
      },
      rules: {},
    };
  },
  computed: {},
  methods: {
    // 重置表单
    resetForm() {
      this.$formClear(this.$refs.form);
      this.activeName = "tab0";
    },
    // 校验表单
    async validateForm() {
      if (!(await this.$formValidateWraper(this.$refs.form))) {
        return false;
      }

      return true;
    },
    // 设置表单数据
    setForm(data) {
      console.log("this", this);
      this.$setFormData(this.formData, data.user, "user");
    },

    // 获取表单数据
    getForm() {
      const formData = {};
      formData.user = this.$getFormData(this.formData, "user");
      return formData;
    },

    async loadFormData({ keyValue /*,params,node*/ }) {
      //  keyValue 流程中相当于流程processId,params 传递参数,node 流程节点
      const data = await this.$awaitWraper(apiUser.get(keyValue));
      if (data) {
        this.setForm(data);
        return true;
      } else {
        return false;
      }
    },

    async saveForm({ keyValue, isEdit /*,code,node*/ }) {
      // isEdit 是否更新数据, keyValue 流程中相当于流程processId,code 表示流程中的操作码,node 流程节点
      const postData = this.getForm();
      if (isEdit) {
        // 编辑
        delete postData.user["f_userid"];
        return await this.$awaitWraper(apiUser.update(keyValue, postData));
      } else {
        // 新增
        // 主键不为字串类型，如果要作为流程表单请手动绑定流程关联字段
        postData.user["f_userid"] = keyValue;
        return await this.$awaitWraper(apiUser.add(postData));
      }
    },
  },
};
</script>
